import requests     # 导入网络请求库

def deepseek(question):
    url = "https://api.siliconflow.cn/v1/chat/completions"  # API地址

    # 字典类型，标识是{"键": "值"}，英文dict
    payload = {     # 要传输的信息（字典）
        "model": "deepseek-ai/DeepSeek-R1-Distill-Qwen-7B",
        "stream": False,
        "max_tokens": 512,
        "temperature": 0.7,
        "top_p": 0.7,
        "top_k": 50,
        "frequency_penalty": 0.5,
        "n": 1,
        "stop": [],
        "messages": [   # []代表列表
            {       # {}代表字典
                "role": "user",     # 角色
                "content": question   # 内容
            }
        ]
    }
    headers = {     # 请求头
        "Authorization": "Bearer sk-ztjdijjdzgjnmilnsbwtogdvadchciehkjgfuspwhirvvvdw",
        "Content-Type": "application/json"
    }
    # http请求包括POST(发送信息)、GET(接收信息)
    response = requests.request("POST", url, json=payload, headers=headers)

    print(response.text)    # 打印返回结果
    # 将打印的结果，复制到1.json。按Ctrl+Alt+L 规范化
    # 可以使用JSON提取回答信息
    print(response.json().get("choices")[0].get("message").get("content"))
